CK: Refactor 144 contraction instance files with shared CK_CONTRACTION_INSTANCE macro#6325
Merged
AviralGoelAMD merged 3 commits intoApr 10, 2026
Conversation
Introduce contraction_instance_common.hpp with a shared macro that generates both the using-alias and add_device_* registration function for contraction instances from 12 parameters. Refactor all 36 bilinear-2D instance files to use the macro, reducing each from 58 to 12 lines. Net savings: 1,656 lines.
Apply CK_CONTRACTION_INSTANCE macro to the remaining 108 instance files: bilinear-6D (36), scale-2D (36), scale-6D (36). Combined with the previous commit, all 144 contraction instance files now use the shared macro. Total savings: ~6,600 lines.
The parent CMakeLists.txt globs all subdirectories (line 218: file(GLOB dir_list LIST_DIRECTORIES true *)) and attempts to file(READ .../contraction/CMakeLists.txt) for each. Without this file, CMake fails: file failed to open for reading: .../gpu/contraction/CMakeLists.txt The contraction/ directory is header-only (contraction_instance_common.hpp). Adding an empty CMakeLists.txt satisfies the glob/read requirement. The directory defines no targets, so add_subdirectory() processes it harmlessly. Fixes Jenkins CI failure on PR #6325.
17dd5a7
into
users/avirgoel/ck/contraction-macro-experiment
31 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Depends on #6324
Summary
Refactor all 144 contraction library instance
.cppfiles (bilinear + scale, 2D/6D, f32/f64/bf16/cf32/cf64) to use a sharedCK_CONTRACTION_INSTANCEmacro defined incontraction_instance_common.hpp. Each 58-line file is reduced to 12 lines — zero unique logic, pure parameterization.What changed
Macro parameters (12)
INST_TPLdevice_contraction_kk_instanceOP_NAMEbilinear##token pasting for function/type namesCDE_OPBilinearNDIM_VAL2or6NAME_SUFFIXf32_f32_f32_f32_kknnADATA..COMPUTEF32, F32, ...Readability assessment
A code realist review confirmed this change improves readability: the original 58-line files contained zero unique logic — just mechanical boilerplate wrappers that varied only in 12 template parameters. After the macro, each file's intent is immediately clear from a single macro call, and the 12 parameters serve as a concise specification of what the instance does (data types, layout, operation). Adding a new contraction instance requires writing 1 line instead of copying and modifying 58 lines. The realist also noted that the area has very low activity (1 functional commit in 18 months), so merge conflict risk is negligible.
Cumulative cleanup series stats
#if 0blocks